package com.hongye.proprietary.controller;

import com.hongye.common.utils.PageUtils;
import com.hongye.common.utils.R;
import com.hongye.proprietary.entity.HongyeOrderEntity;
import com.hongye.proprietary.service.HongyeOrderService;
import com.hongye.proprietary.vo.PayAsyncVo;
import com.hongye.proprietary.vo.RequirementVo;
import com.hongye.proprietary.vo.SaleHomeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;



/**
 * 订单表
 *
 * @author lins
 * @email 695565697@qq.com
 * @date 2021-10-14 11:16:47
 */
@RestController
@RequestMapping("proprietary/order")
public class HongyeOrderController {
    @Autowired
    private HongyeOrderService orderService;
    /*
    * 查询订单状态
    * */
    @RequestMapping("getOrderStatus")
    public Integer getOrderStatus(@RequestParam Integer orderId){
        HongyeOrderEntity entity = orderService.getById(orderId);
        return entity.getOrderStatus();
    }

    /*
    * 收到支付宝异步回调消息,修改订单状态
    */
    @RequestMapping("notify")
    public String notify(@RequestBody PayAsyncVo payAsyncVo){
        return orderService.payNotify(payAsyncVo);
    }
    /*
    * 订单发布页信息
    * */
    @RequestMapping("confirmOrder")
    public R confirmOrder(){
        return orderService.confirmOrder();
    }
    /*
    * 提交订单并支付
    * */
    @RequestMapping("submitOrder")
    public R submitOrder(@RequestBody RequirementVo requirementVo){
        return orderService.submitOrder(requirementVo);
    }
    /*
    * 提交业主订单并支付
    * */
    @RequestMapping("submitOwnerOrder")
    public R submitOwnerOrder(@RequestBody SaleHomeVo saleHomeVo){
        return orderService.submitOwnerOrder(saleHomeVo);
    }

    /**
     * 列表
     */
    @RequestMapping("/getOrderList")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{orderId}")
    public R info(@PathVariable("orderId") Integer orderId){
		HongyeOrderEntity order = orderService.getById(orderId);

        return R.ok().put("order", order).put("orderSn", order.getOrderNumber()).put("price", order.getOrderPrice());
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HongyeOrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HongyeOrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] orderIds){
		orderService.removeByIds(Arrays.asList(orderIds));

        return R.ok();
    }

}
